#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
简单的Flask Web应用来展示分析结果
"""

from flask import Flask, render_template_string, send_from_directory
import os
import json

app = Flask(__name__)

@app.route('/')
def index():
    """主页面"""
    with open('index.html', 'r', encoding='utf-8') as f:
        html_content = f.read()
    return html_content

@app.route('/static/<path:filename>')
def static_files(filename):
    """静态文件服务"""
    return send_from_directory('static', filename)

@app.route('/data')
def get_data():
    """获取分析数据"""
    try:
        with open('analysis_results.json', 'r', encoding='utf-8') as f:
            return json.load(f)
    except FileNotFoundError:
        return {"error": "分析结果文件不存在"}

if __name__ == '__main__':
    print("🚀 启动学生社交媒体分析网页服务...")
    print("📊 网页地址: http://localhost:5000")
    print("📋 数据API: http://localhost:5000/data")
    print("⏹️  按 Ctrl+C 停止服务")
    
    app.run(host='0.0.0.0', port=5000, debug=True)
